const mongoose = require('mongoose')

// mongoose.connect('mongodb://111.229.157.253:27017/hitea')
mongoose.connect('mongodb://127.0.0.1:27017/hitea')

const users = mongoose.model('users', { 
    username: {type:String, required: true}, 
    password: {type:Number, required: true}, 
    tximg: {type:String, default:''},
    orderId: {type:String, default:''},
    vip: {type: Number, default: 0}
})

// const admin = mongoose.model('users', { 
//     username: {type:String, required: true}, 
//     password: {type:Number, required: true}, 
// })

const orders = mongoose.model('orders', { name: String, age: Number })

const token = mongoose.model('token', {
    token:{type:String, required: true},
    createAt:{type:Date,default:Date.now, index:{expires:1080000}}
},"token")

const goods = mongoose.model('goods', { 
    title: String, 
    data: [{
        title: String,
        tag: [String],
        des: String,
        price: Number,
        img: String
    }] 
})

// Cat.create({name: 'tom',age:487}).then(()=>console.log('ok'))
// Cat.find({},{name:1,_id:0}).then((data)=>console.log(data))
// Cat.updateMany({name:'tom'},{age:'66'}).then(()=>console.log('update ok'))
// Cat.deleteMany({_id:'619326f20a11be7cb8b4a4a0'}).then(()=>console.log('remove ok'))

module.exports = {
    users, orders, goods, token
}